package com.xr.miniprogram.domain.vo;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.xr.miniprogram.domain.MiniProgramStandards;
import lombok.Data;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * description: 服务规格VO，处理inputForm
 *
 * @author: wls
 * @date: 2023/12/7 10:57
 * @version:1.0
 */
@Data
public class MiniProgramStandardsVO {
    private Long serviceStandardsId;
    /** 服务详情id */
    private Long serviceId;
    /** 规格图 */
    private String standardsImg;
    /** 规格名 */
    private String standardsName;
    /** 原价 */
    private BigDecimal standardsOriginalPrice;
    /** 介绍 */
    private String standardsTips;
    /** 单位 */
    private String standardsUnit;
    /** 含带服务次数 */
    private Long number;
    /** 可否多选 */
    private Long multiple;
    /** 是否开启折扣 */
    private Long discount;
    /** 折扣率 */
    private Double depositRate;
    /** 规格版本 */
    private Long standardsVersion;
    /** 输入表单 */
    private List<StandardsInputForm> inputForm;
    /** 创建者 */
    private String createBy;
    /** 创建时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    /** 更新者 */
    private String updateBy;
    /** 更新时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    public static MiniProgramStandardsVO toMiniProgramStandardsVO(MiniProgramStandards item){
        MiniProgramStandardsVO vo = new MiniProgramStandardsVO();
        vo.setServiceStandardsId(item.getServiceStandardsId());
        vo.setServiceId(item.getServiceId());
        vo.setStandardsImg(item.getStandardsImg());
        vo.setStandardsName(item.getStandardsName());
        vo.setStandardsOriginalPrice(item.getStandardsOriginalPrice());
        vo.setStandardsTips(item.getStandardsTips());
        vo.setStandardsUnit(item.getStandardsUnit());
        vo.setNumber(item.getNumber());
        vo.setMultiple(item.getMultiple());
        vo.setDiscount(item.getDiscount());
        vo.setDepositRate(item.getDepositRate());
        vo.setStandardsVersion(item.getStandardsVersion());
        vo.setInputForm(JSON.parseArray(item.getInputForm(), StandardsInputForm.class));
        vo.setCreateBy(item.getCreateBy());
        vo.setCreateTime(item.getCreateTime());
        vo.setUpdateBy(item.getUpdateBy());
        vo.setUpdateTime(item.getUpdateTime());
        return vo;
    }

    public static List<MiniProgramStandardsVO> toMiniProgramStandardsVOList(List<MiniProgramStandards> itemList){
        List<MiniProgramStandardsVO> voList = new ArrayList<>();
        for (MiniProgramStandards item : itemList) {
            voList.add(MiniProgramStandardsVO.toMiniProgramStandardsVO(item));
        }
        return voList;
    }

    public MiniProgramStandards toMiniProgramStandards(){
        MiniProgramStandards item = new MiniProgramStandards();
        item.setServiceStandardsId(serviceStandardsId);
        item.setServiceId(serviceId);
        item.setStandardsImg(standardsImg);
        item.setStandardsName(standardsName);
        item.setStandardsOriginalPrice(standardsOriginalPrice);
        item.setStandardsTips(standardsTips);
        item.setStandardsUnit(standardsUnit);
        item.setNumber(number);
        item.setMultiple(multiple);
        item.setDiscount(discount);
        item.setDepositRate(depositRate);
        item.setStandardsVersion(standardsVersion);
        item.setInputForm(JSON.toJSONString(inputForm));
        item.setCreateBy(createBy);
        item.setCreateTime(createTime);
        item.setUpdateBy(updateBy);
        item.setUpdateTime(updateTime);
        return item;
    }
}
